<template>
  <div class="responsive-table-container">
    <div>
    <span>
      <el-input ref='searchInput' v-model="NameOrStudentAccount" autocapitalize="off" autocomplete="off" autocorrect="off" autofocus clearable icon="Search" placeholder="搜索..." spellcheck="false" style="width: 30%;" type="text" @change="getAllStudent"/>
      <el-button icon="search" style="position: relative; left: 5px" type="primary" @click="getAllStudent">搜索</el-button>
      <el-button icon="plus" type="success" @click="addStudent('student')">添加学生</el-button>
      <el-button type="primary" @click="exportToExcel">导出Excel</el-button>
    </span>
    </div>
    <div style="overflow-y: hidden;overflow-x: auto; ">
      <el-table lazy="lazy" height="80vh" max-height="90vh" ref="selectedRow" stripe :cell-style="{'text-align':'center'}" :data="StudentMessage" :header-cell-style="{'text-align':'center'}" border row-key="id" v-model="selectedRow" @selection-change="handleSelectionChange" @filter-change="filterChange" style="width: 100%">
        <el-table-column type="selection" :reserve-selection="true" width="55">
        </el-table-column>
        <el-table-column fixed width="80" type="index" align="center" :index="1">
          <template #header>
            <el-popover placement="bottom" :width="600" :visible="visible">
              <!-- 配置列面板 -->
              <transition name="fade">
                <div>
                  <div>选择显示信息</div>
                  <div>
                    <div><el-checkbox v-model="selectAll" @change="selectAllCheck">全选</el-checkbox></div>
                    <el-checkbox v-model="StudentMessageCanLook.photoImage">照片</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.accountNo" >学号</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.gradeNo" >年级</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.name">姓名</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.namePinyin">姓名拼音</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.sex">性别</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.classNo">班级</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.departmentName">学院</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.majorName">专业名称</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.headTeacher">班主任</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.instructorName">辅导员</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.contact">联系方式</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.email">电子邮箱</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.addressOfHousehold">家庭住址</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.studentCategory">学生类别</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.enrollmentDate">入学日期</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.admissionMethod">入学方式</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.qq">QQ号</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.birthdate">出生日期</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.nativePlaceProvince">籍贯</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.polstatusName">政治面貌</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.joinTime">加入时间</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.thnic">民族</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.idnumber">证件号</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.foreignLanguage">外语类别</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.height">身高</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.weight">体重</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.comprehensiveAssessmentRanking">综测排名</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.scoreRanking">成绩排名</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.dormitoryBuilding">宿舍楼栋</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.dormitoryNumber">寝室号</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.isInSchool">是否在校</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.guardian1">监护人1</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.guardian1">监护人1联系方式</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.guardian2">监护人2</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.guardian2">监护人2联系方式</el-checkbox>
                    <el-checkbox v-model="StudentMessageCanLook.notes">备注</el-checkbox>
                  </div>
                </div>
              </transition>
              <div style="text-align: right; margin: 0">
                <el-button size="small" type="primary" plain @click="saveColumn">确定</el-button>
              </div>
              <template #reference>
                <el-button icon="setting" class="el-icon-setting" style="font-size: 22px; cursor: pointer" @click="visible = true"></el-button>
              </template>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="照片" prop="photoImage" width="70" v-if="StudentMessageCanLook.photoImage">
          <template v-slot="scope"><img width="35" height="50" v-if="scope.row.photoImage" :src="photoIp()+scope.row.photoImage" class="avatar"></template>
        </el-table-column>
        <el-table-column width="120" :sortable="true" label="学号" prop="accountNo"  v-if="StudentMessageCanLook.accountNo"/>
        <el-table-column width="100" :sortable="true" label="姓名" prop="name"  v-if="StudentMessageCanLook.name"/>
        <el-table-column width="180" :sortable="true" label="姓名拼音" prop="namePinyin"  v-if="StudentMessageCanLook.namePinyin"/>
        <el-table-column width="100" :sortable="true" :filter-method="FilterHandler" :filter-multiple="false" label="性别" :filters="sexHeaderSelect" prop="sex"  v-if="StudentMessageCanLook.sex"/>
        <el-table-column width="120" :sortable="true" label="班级" prop="classNo" v-if="StudentMessageCanLook.classNo"/>
        <el-table-column width="120" :sortable="true" :filter-method="FilterHandler" :filter-multiple="false" label="年级" :filters="gradeNoHeaderSelect" prop="gradeNo" v-if="StudentMessageCanLook.gradeNo"/>
        <el-table-column width="120" :sortable="true" :filter-method="FilterHandler" :filter-multiple="false"  label="政治面貌" :filters="polstatusHeaderSelect" prop="polstatusName" v-if="StudentMessageCanLook.polstatusName"/>
        <el-table-column width="120" :sortable="true" label="加入时间" prop="joinTime" v-if="StudentMessageCanLook.joinTime"/>
        <el-table-column width="120" :sortable="true" label="联系方式" prop="contact" v-if="StudentMessageCanLook.contact"/>
        <el-table-column width="120" :sortable="true" label="监护人1" prop="guardian1" v-if="StudentMessageCanLook.guardian1"/>
        <el-table-column width="180" :sortable="true" label="监护人1联系方式" prop="guardian1Contact" v-if="StudentMessageCanLook.guardian1"/>
        <el-table-column width="120" :sortable="true" label="监护人2" prop="guardian2" v-if="StudentMessageCanLook.guardian2"/>
        <el-table-column width="180" :sortable="true" label="监护人2联系方式" prop="guardian2Contact" v-if="StudentMessageCanLook.guardian2"/>
        <el-table-column width="120" :sortable="true" :filter-method="FilterHandler" :filter-multiple="false" label="班主任" :filters="headTeacherHeaderSelect" prop="headTeacher" v-if="StudentMessageCanLook.headTeacher"/>
        <el-table-column width="120" :sortable="true" :filter-method="FilterHandler" :filter-multiple="false" label="辅导员" :filters="instructorNameHeaderSelect" prop="instructorNo" v-if="StudentMessageCanLook.instructorName"/>
        <el-table-column width="120" :sortable="true" :filter-method="FilterHandler" :filter-multiple="false"  label="宿舍楼栋" :filters="dormitoryBuildingHeaderSelect" prop="dormitoryBuilding" v-if="StudentMessageCanLook.dormitoryBuilding"/>
        <el-table-column width="120" :sortable="true" label="寝室号" prop="dormitoryNumber" v-if="StudentMessageCanLook.dormitoryNumber"/>
        <el-table-column width="120" :sortable="true" :filter-method="FilterHandler" :filter-multiple="false" label="民族" :filters="thnicHeaderSelect" prop="thnic" v-if="StudentMessageCanLook.thnic"/>
        <el-table-column width="180" :sortable="true" :filter-method="FilterHandler" :filter-multiple="false" label="专业名称" :filters="majorNameHeaderSelect" prop="majorName" v-if="StudentMessageCanLook.majorName"/>
        <el-table-column width="120" :sortable="true" label="出生日期" prop="birthdate" sortable lable="Date"  v-if="StudentMessageCanLook.birthdate"/>
        <el-table-column width="120" :sortable="true" :filter-method="FilterHandler" :filter-multiple="false" label="学院" :filters="departmentNameHeaderSelect" prop="departmentName" v-if="StudentMessageCanLook.departmentName"/>
        <el-table-column width="120" :sortable="true" :filter-method="FilterHandler" :filter-multiple="false" label="学制" :filters="educationalSystemHeaderSelect" prop="educationalSystem"  v-if="StudentMessageCanLook.educationalSystem"/>
        <el-table-column width="180" :sortable="true" label="电子邮箱" prop="email" v-if="StudentMessageCanLook.email"/>
        <el-table-column width="180" :sortable="true" label="QQ号" prop="qq" v-if="StudentMessageCanLook.qq"/>
        <el-table-column width="200" :sortable="true" label="证件号" prop="idnumber" v-if="StudentMessageCanLook.idnumber"/>
        <el-table-column width="280" :sortable="true" label="家庭住址" prop="addressOfHousehold" v-if="StudentMessageCanLook.addressOfHousehold"/>
        <el-table-column width="120" :sortable="true" :filter-method="FilterHandler" :filter-multiple="false" label="学生类别" :filters="studentCategoryHeaderSelect" prop="studentCategory" v-if="StudentMessageCanLook.studentCategory"/>
        <el-table-column width="120" :sortable="true" label="入学日期" prop="enrollmentDate" v-if="StudentMessageCanLook.enrollmentDate"/>
        <el-table-column width="120" :sortable="true" :filter-method="FilterHandler" :filter-multiple="false"  label="入学方式" :filters="admissionMethodHeaderSelect" prop="admissionMethod" v-if="StudentMessageCanLook.admissionMethod"/>
        <el-table-column width="120" :sortable="true" label="籍贯" prop="nativePlaceProvince" v-if="StudentMessageCanLook.nativePlaceProvince"/>
        <el-table-column width="120" :sortable="true" label="是否在校" prop="isInSchool" v-if="StudentMessageCanLook.isInSchool"/>
        <el-table-column width="120" :sortable="true" :filter-method="FilterHandler" :filter-multiple="false" label="外语类别" :filters="foreignLanguageHeaderSelect" prop="foreignLanguage" v-if="StudentMessageCanLook.foreignLanguage"/>
        <el-table-column width="120" :sortable="true" label="身高" prop="height" v-if="StudentMessageCanLook.height"/>
        <el-table-column width="120" :sortable="true" label="体重" prop="weight" v-if="StudentMessageCanLook.weight"/>
        <el-table-column width="120" :sortable="true" label="国测成绩" prop="sportGrade" v-if="StudentMessageCanLook.sportGrade"/>
        <el-table-column width="120" :sortable="true" label="备注" prop="notes" v-if="StudentMessageCanLook.notes"/>
        <el-table-column width="120" :sortable="true" label="综测排名" prop="comprehensiveAssessmentRanking" v-if="StudentMessageCanLook.comprehensiveAssessmentRanking"/>
        <el-table-column width="120" :sortable="true" label="成绩排名" prop="scoreRanking" v-if="StudentMessageCanLook.scoreRanking"/>
        <el-table-column fixed="right" class="operate" label="操作" prop="operate" width="120"><template v-slot="scope"><el-button icon="Edit" size="small" type="primary" @click="popoverVisible=true;this.scope=scope.row">操作</el-button></template></el-table-column>
      </el-table>
    </div>
    <el-pagination class="pagination" :page-size="pageSize" small :pager-count="5" :page-sizes="[50, 100 , 200 , 500,1000,2000,5000]" :total="total" layout="total, sizes, prev, pager, next" @size-change="handleSizeChange" @current-change="handleCurrentChange"></el-pagination>
    <el-dialog width="220" v-model="popoverVisible">
      <div>
        <el-button icon="Search" size="small" type="success" @click="detailedInformation1(this.scope)">查看详情</el-button>
        <el-button size="small" type="warning" icon="Refresh" @click="resetPass(this.scope)">重置密码</el-button>
        <br>
        <el-button icon="Delete" size="small" type="danger" @click="deleteStudent(this.scope)">删除学生</el-button>
        <el-button icon="Edit" size="small" type="primary" @click="this.$router.push({path:'/UploadMessage',query: {accountNo:this.scope.accountNo}})">修改信息</el-button>
      </div>
    </el-dialog>
    <el-dialog v-model="detailedInformation" :close-on-click-modal="false" title="学生详细信息" width="850px">
      <information v-if="detailedInformation" ref="dialog"/>
    </el-dialog>
    <el-dialog title="新增学生" width="500" v-model="this.addStudentDialog">
      <el-form :model="this.addStudentForm" :rules="addStudentFormRules" ref="addStudentForm">
        <el-form-item label="学号" prop="accountNo">
          <el-input v-model="this.addStudentForm.accountNo" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="this.addStudentForm.name" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="addStudentCancel('addStudentForm')">取 消</el-button>
        <el-button type="primary" @click="addStudent('addStudentForm')">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="新增老师" width="500" v-model="this.addTeacherDialog">
      <el-form :model="this.addTeacherForm" :rules="addTeacherFormRules" ref="addStudentForm">
        <el-form-item label="工号" prop="accountNo">
          <el-input v-model="this.addTeacherForm.accountNo" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="this.addTeacherForm.name" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="addTeacherCancel('addStudentForm')">取 消</el-button>
        <el-button type="primary" @click="addTeacher('addStudentForm')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import request from "@/util/request.js";
import Information from "@/template/Information.vue";
import * as XLSX from 'xlsx'
import {photoIp} from "../../../public/static/config.js";

export default {
  components: {Information},
  data() {
    return {
      scope: {},
      popoverVisible: false, // 操作显示
      flag: false,  // 判断是否被筛选
      selectedRow: [], // 选中行
      selectAll: false,
      visible: false,
      detailedInformation: false,  // 学生详情弹窗
      addStudentDialog: false,  // 新增学生弹窗
      addTeacherDialog: false, //新增老师弹窗
      addStudentForm: {},  // 新增学生信息
      addTeacherForm: {},  // 新增老师信息
      addStudentFormRules: {
        accountNo: [
          {required: true, message: '请输入学号', trigger: 'blur'}
        ],
        name: [
          {required: true, message: '请输入姓名', trigger: 'blur'}
        ]
      },
      addTeacherFormRules:{
        accountNo: [
          {required: true, message: '请输入工号', trigger: 'blur'}
        ],
        name: [
          {required: true, message: '请输入姓名', trigger: 'blur'}
        ]
      },
      StudentMessage: [],
      information: {},
      NameOrStudentAccount: "",
      command: '全部',
      pageNum: 1, //页码
      pageSize: 50,  //页长
      total: 0,  //总表长
      instructorNameAll: [],
      instructorName: [],
      text: "",
      value: "",
      StudentMessageCanLook:{
        photoImage: true,
        accountNo:true,
        name:true,
        namePinyin:false,
        gradeNo:true,
        sex:true,
        classNo:true,
        instructorName:true,
        contact:true,
        qq:true,
        birthdate:true,
        polstatusName:true,
        joinTime: true,
        thnic:true,
        departmentName:false,
        majorName:true,
        addressOfHousehold:true,
        studentCategory:true,
        nativePlaceProvince:true,
        educationalSystem:true,
        admissionMethod:true,
        dormitoryNumber:true,
        dormitoryBuilding:true,
        enrollmentDate:true,
        isInSchool:false,
        headTeacher:true,
        sportGrade:true,
        idnumber:true,
        email:true,
        foreignLanguage:true,
        height:false,
        weight:false,
        comprehensiveAssessmentRanking:true,
        scoreRanking:true,
        notes:true,
        guardian1:true,
        guardian2:true,
      },
      // 政治面貌选择器内容
      polstatusHeaderSelect: [{
        text: '中共党员',
        value: '中共党员'
      }, {
        text: '中共预备党员',
        value: '中共预备党员'
      }, {
        text: '党员发展对象',
        value: '党员发展对象'
      }, {
        text: '入党积极分子',
        value: '入党积极分子'
      }, {
        text: '共青团员',
        value: '共青团员'
      }, {
        text: '入团发展对象',
        value: '入团发展对象'
      }, {
        text: '入团积极分子',
        value: '入团积极分子'
      }, {
        text: '群众',
        value: '群众'
      },{
        text: '其他',
        value: '其他'
      }],
      sexHeaderSelect: [{
        text: '男',
        value: '男'
      }, {
        text: '女',
        value: '女'
      },{
        text: '其他',
        value: '其他'
      }],
      gradeNoHeaderSelect: [{
        text: '2021',
        value: '2021'
      }, {
        text: '2022',
        value: '2022'
      },{
        text: '2023',
        value: '2023'
      },{
        text: '2024',
        value: '2024'
      },{
        text: '其他',
        value: '其他'
      }],
      thnicHeaderSelect: [{
        text: '汉族',
        value: '汉族'
      },{
        text: '其他',
        value: '其他'
      }],
      departmentNameHeaderSelect: [{
        text: '信息工程学院',
        value: '信息工程学院'
      },{
        text: '其他',
        value: '其他'
      }],
      majorNameHeaderSelect: [{
        text: '计算机科学与技术',
        value: '计算机科学与技术'
      },{
        text: '物联网工程',
        value: '物联网工程'
      },{
        text: '电子信息工程',
        value: '电子信息工程'
      },{
        text: '通信工程',
        value: '通信工程'
      },{
        text: '软件工程',
        value: '软件工程'
      },{
        text: '轨道交通信号与控制',
        value: '轨道交通信号与控制'
      },{
        text: '其他',
        value: '其他'
      }],
      educationalSystemHeaderSelect: [{
        text: '4年',
        value: '4年'
      },{
        text: '5年',
        value: '5年'
      },{
        text: '其他',
        value: '其他'
      }],
      studentCategoryHeaderSelect: [{
        text: '专升本',
        value: '专升本'
      },{
        text: '对口升学',
        value: '对口升学'
      },{
        text: '普通本科',
        value: '普通本科'
      },{
        text: '其他',
        value: '其他'
      }],
      admissionMethodHeaderSelect: [{
        text: '专升本',
        value: '专升本'
      },{
        text: '对口升学',
        value: '对口升学'
      },{
        text: '统招入学',
        value: '统招入学'
      },{
        text: '其他',
        value: '其他'
      }],
      dormitoryBuildingHeaderSelect: [{
        text: '6号楼',
        value: '6号楼'
      },{
        text: '9号楼',
        value: '9号楼'
      },{
        text: '文瀚苑',
        value: '文瀚苑'
      },{
        text: '文泽苑',
        value: '文泽苑'
      },{
        text: '文瀛苑',
        value: '文瀛苑'
      },{
        text: '文鸿苑',
        value: '文鸿苑'
      },{
        text: '文涛苑',
        value: '文涛苑'
      },{
        text: '文澜苑',
        value: '文澜苑'
      },{
        text: '文灏苑',
        value: '文灏苑'
      },{
        text: '其他',
        value: '其他'
      }],
      foreignLanguageHeaderSelect: [{
        text: '英语',
        value: '英语'
      },{
        text: '日语',
        value: '日语'
      },{
        text: '其他',
        value: '其他'
      }],
      instructorNameHeaderSelect: [{
        text: '杨燕飞',
        value: '杨燕飞'
      },{
        text: '边志巧',
        value: '边志巧'
      },{
        text: '贺少伟',
        value: '贺少伟'
      },{
        text: '李艳玲',
        value: '李艳玲'
      },{
        text: '张小丫',
        value: '张小丫'
      },{
        text: '陈婷',
        value: '陈婷'
      },{
        text: '其他',
        value: '其他'
      }],
      headTeacherHeaderSelect: [{
        text: '史静珮',
        value: '史静珮'
      },{
        text: '孟学尧',
        value: '孟学尧'
      },{
        text: '边志巧',
        value: '边志巧'
      },{
        text: '李晓君',
        value: '李晓君'
      },{
        text: '曹俊斌',
        value: '曹俊斌'
      },{
        text: '武蕊蕊',
        value: '武蕊蕊'
      },{
        text: '贺少伟',
        value: '贺少伟'
      },{
        text: '姚慧婷',
        value: '姚慧婷'
      },{
        text: '韩  鹤',
        value: '韩  鹤'
      },{
        text: '贺养慧',
        value: '贺养慧'
      },{
        text: '李艳玲',
        value: '李艳玲'
      },{
        text: '高伟萍',
        value: '高伟萍'
      },{
        text: '边志巧',
        value: '边志巧'
      },{
        text: '常芳',
        value: '常芳'
      },{
        text: '张小丫',
        value: '张小丫'
      },{
        text: '高俊',
        value: '高俊'
      },{
        text: '林慧龙',
        value: '林慧龙'
      },{
        text: '杨青',
        value: '杨青'
      },{
        text: '杨燕飞',
        value: '杨燕飞'
      },{
        text: '陈婷',
        value: '陈婷'
      },{
        text: '卢鑫',
        value: '卢鑫'
      },{
        text: '其他',
        value: '其他'
      }],
    };
  },



  //初始化加载
  created() {
    this.getAllStudent(); //加载所有学生的所有信息
  },
  methods: {
    photoIp() {
      return photoIp
    },
    // 选行
    handleSelectionChange(val) {
      this.selectedRow = val;
    },
    exportToExcel() {
      this.$nextTick(() => {
        // 获取 el-table 中的当前显示数据
        const tableData = this.selectedRow
        // 确保数据存在
        if (tableData && tableData.length > 0) {
          // 获取选择的列，并按顺序存储到数组中
          const selectedColumns = [];
          for (const key in this.StudentMessageCanLook) {
            if (this.StudentMessageCanLook[key]) {
              selectedColumns.push(key);
            }
          }

          // 过滤数据，只保留选中的列并按照顺序存储到数组中
          const filteredData = tableData.map(row => {
            const filteredRow = {};
            selectedColumns.forEach(column => {
              filteredRow[column] = row[column] !== undefined ? row[column] : '';
            });
            return filteredRow;
          });

          // 将数据转换为 Excel 格式
          const worksheet = XLSX.utils.json_to_sheet(filteredData);
          const workbook = XLSX.utils.book_new();
          XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');

          // 下载 Excel 文件
          XLSX.writeFile(workbook, 'student_data.xlsx');
        } else {
          // 提示用户没有数据可供导出
          alert('没有数据可供导出！');
        }
      });
    },
    // 删除学生
    deleteStudent(scope) {
      this.$confirm('此操作将永久删除该学生, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        request.get("/info_account/deleteByAccountNo?accountNo=" + scope.accountNo).then(res => {
          if (res.data.code === '200') {
            this.$message({
              type: 'success',
              message: '删除成功',
            });
            location.reload()
          }
        })
      })
    },
    // 新增学生
    addStudent(addStudentForm) {
      this.addStudentDialog = true;
      this.$refs[addStudentForm].validate((valid) => {
        if (valid) {
          // 发送 POST 请求到服务器
          request.post('/info_account/addStudent', this.addStudentForm).then(res => {
            if (res.data.code === '200') {
              // 关闭对话框
              this.addStudentDialog = false;
              location.reload()
              // 显示成功消息
              this.$message({
                type: 'success',
                message: '新增成功!'
              });
            } else {
              this.$message({
                type: 'error',
                message: '该学生信息已存在'
              });
            }
          })
        }
      });
    },
    // 新增老师
    addTeacher(addTeacherForm) {
      this.addTeacherDialog = true;
      this.$refs[addTeacherForm].validate((valid) => {
        if (valid) {
          // 发送 POST 请求到服务器
          request.post('/info_account/addTeacher', this.addTeacherForm).then(res => {
            if (res.data.code === '200') {
              // 关闭对话框
              this.addTeacherDialog = false;
              location.reload()
              // 显示成功消息
              this.$message({
                type: 'success',
                message: '新增成功!'
              });
            } else {
              this.$message({
                type: 'error',
                message: '该老师信息已存在'
              });
            }
          })
        }
      });
    },
    addStudentCancel(addStudentForm) {
      this.addStudentDialog = false;
      this.addStudentForm = {}
      this.$refs[addStudentForm].resetFields();
    },
    addTeacherCancel(addTeacherForm) {
      this.addTeacherDialog = false;
      this.addTeacherForm = {}
      this.$refs[addTeacherForm].resetFields();
    },
    selectAllCheck() {
      // 设置所有复选框的选中状态
      Object.keys(this.StudentMessageCanLook).forEach((key) => {
        this.StudentMessageCanLook[key] = this.selectAll;
      });
    },
    saveColumn() {
      localStorage.setItem("columnSet",JSON.stringify(this.showColumn))
      this.visible = false;
    },
    detailedInformation1(scope) {
      this.information = scope
      this.detailedInformation = true
      window.getTemplateData = (callback) => {
        this.getTemplateData(callback);
      }
    },
    getTemplateData(callback) {
      callback(this.information);
    }, //获取文书数据

    //按学号或姓名模糊查询学生/获取所有学生信息
    getAllStudent() {
      request.get("/info_account/page?name=" + this.NameOrStudentAccount + "&accountNo=" + this.NameOrStudentAccount + "&pageNum=" + this.pageNum + "&pageSize=" + this.pageSize).then(res => {
        if (res.data.code === '200') {
          for (let key in res.data.data) {
            if (key === "records") {
              this.StudentMessage = res.data.data[key];
            } else if (key === "total") {
              this.total = res.data.data[key];
            }
          }
        }
      })
    },
    resetPass(scope) {
      this.$confirm('您确定要将该用户密码重置吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        request.post("/account/resetPwd",scope.accountNo).then(res => {
          if (res.data.code === '200') {
            this.$message({
              type: 'success',
              message: '重置成功!默认密码为学号',
            });
          } else {
            this.fail();
          }
        })
      })
    },
    //表尾分页
    handleSizeChange(val) {
      this.pageSize = val;
      this.getAllStudent();
    },
    handleCurrentChange(val) {
      this.pageNum = val;
      this.getAllStudent();
    },
    filterChange(filter) {
      this.$refs.selectedRow.clearSelection()
    },
    FilterHandler(value, row, column) {
      const property = column['property'];
      // 如果值是“其他”，则返回除了已有选项之外的字段
      if (value === '其他') {
        return !column['filters'].some(filter => filter.value === row[property]);
      }
      // 否则按照正常逻辑进行筛选
      return row[property] === value;
    }
  },
};

</script>
